package com.dyz.leetcode._19_greedy;

public class _680_validPalindrome {
    //暴力解法 超时
    public boolean validPalindrome1(String s) {
        for (int i = -1; i < s.length(); i++) {
            int left = 0; int right=s.length()-1;
            boolean ishuifen = true;
            while (left<right){
                if(left==i){left++;}
                if(right==i){right--;}

                if(s.charAt(left) == s.charAt(right)){
                    left++;
                    right--;
                }else {
                    ishuifen = false;
                }
            }
            if(ishuifen){return true;}

        }
    return false;
    }

    public boolean validPalindrome(String s) {
        int left=0;
        int right = s.length()-1;
        while (left<right){
            if(s.charAt(left)== s.charAt(right)){
                left++;
                right--;
            }else {
                return validPalindrome(s, left+1, right) || validPalindrome(s, left, right-1);
            }
        }
        return true;
    }

    public boolean validPalindrome(String s, int left, int right){
        while (left < right) {
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }

        return true;
    }

}
